
package com.wwy.monitor.controller;

import com.alibaba.buc.sso.client.util.SimpleUserUtil;
import com.alibaba.buc.sso.client.vo.BucSSOUser;
import com.wwy.monitor.common.BizResult;
import com.wwy.monitor.common.ServiceResponse;
import com.wwy.monitor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by gezhen
 */
@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("info")
    public ServiceResponse get(HttpServletRequest request) throws IOException, ServletException {
        //从buc获取用户信息
        BucSSOUser user = SimpleUserUtil.getBucSSOUser(request);
        return ServiceResponse.success(user);
    }

    @RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public BizResult getUsers(@RequestParam(name = "w", required = false) String keyword,
                              @RequestParam(defaultValue = "10") Integer size) throws Exception {
        return BizResult.view(userService.findByKeywordAndSize(keyword, size));
    }
}